package com.hnkywl.sts.dao.cwgl;

import net.ruixin.orm.hibernate.SimpleHibernateTemplate;
import org.hibernate.tool.hbm2x.StringUtils;
import org.hibernate.transform.Transformers;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by ccr on 2014/7/9.
 */
@Repository
public class RjbysDao extends SimpleHibernateTemplate{
    public List rjbysList(String gs) {
        String sql = "select b.id \"rjbys.id\",a.type \"rjbys.type\",a.sbgs_id \"rjbys.sbgsId\",a.sbgs_mc \"rjbys.sbgsMc\",a.kmdm \"rjbys.kmdm\",b.dm \"rjbys.dm\",b.fgf \"rjbys.fgf\"" +
                "  from (select distinct type, sbgs_id, sbgs_mc, kmdm " +
                "  from t_biz_zjfz_rjb) a  " +
                "  left join t_biz_zjfz_rjbys b on (a.type = b.type and a.sbgs_id = b.sbgs_id and a.kmdm = b.kmdm) " +
                (StringUtils.isNotEmpty(gs) ? ("  where a.sbgs_mc like '%" + gs + "%'") : "") +
                "  order by a.type";
        List r = createSQLQuery(sql)
                .setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP)
                .list();
        return r;
    }
}
